﻿/////////////////////////////////////////////////////////////////
//File: BlogManager.cs
//Description: 此文件是根据facade模式和接口隔离原则创建的。各个子业务之间的关联在这里建立。 
//            
//Copyright© 2011 Moliu
//History:
//  2011-3-26 18:11:20    CodeSmith5.0.1    Original Version
//  2011-3-26 19:26:20    Moliu             1
//  2011-4-17 13:13:15    Moliu             2
//  2011-4-23 12:21:49    Moliu             3
//  2011-4-22 22:10:12    Moliu             4
/////////////////////////////////////////////////////////////////
using System;
using System.Collections.Generic;

using MAF.Common;
using My.Blog.Domain.Entities;
using MAF.CRUD;
using My.Blog.Database;

namespace My.Blog.Business.Service
{
    public partial class BlogSvc : BusinessCRUD<BlogInfo>,ICRUD<BlogInfo>
    {
        #region 构造函数
        public BlogSvc() : base(StorageFactory.GetInstance(module).CreateBlog()) { }
        #endregion

        #region IBlog 成员

        /// <summary>
        /// 
        /// </summary>
        /// <param name="info"></param>
        /// <returns></returns>
        public override void CreateBlog(BlogInfo info )
        {
            info.CreatedOn = DateTime.Now;
            info.IsPublished = true;

            info.Name = (null == info.Name) ? "" : info.Name.Trim();
            if( string.Empty==info.Name )
                throw new ArgumentException("博客名字不能为空！");

            info.Owner = (null == info.Owner) ? "" : info.Owner.Trim();
            if (string.Empty == info.Owner)
                throw new ArgumentException("登录名不能为空！");

            object obj = null;
            CategoryInfo cat = new CategoryInfo();
            cat.CreatedOn = DateTime.Now;
            cat.IsPublished = true;
            cat.ParentId = 0;
            using (TransactionScope ts = new TransactionScope())  //曾遇到错误,net start msdtc后解决
            {
                obj = _Blog.CreateBlog(info);

                cat.BlogId = (int)obj;
                cat.Title = obj.ToString();
                
                ICategory _CategoryDao = DaoFactory.Instance.CreateCategory();
                _CategoryDao.CreateCategory(cat);

                ts.Complete();
            }

            return obj;
        }
        
        /// <summary>
        /// 
        /// </summary>
        /// <param name="info"></param>
        /// <returns></returns>
        public int UpdateBlog(BlogInfo info )
        {
            info.DateModified = DateTime.Now;
            return _Blog.UpdateBlog(info);
        }

        #endregion
   
 

        #region IBlog 成员

        public int UpdateBlogName(BlogInfo info)
        {
            //info.DateModified = DateTime.Now;
            //return _Blog.UpdateBlogName(info);
            throw new NotImplementedException();
        }

        public int UpdateBlogIntroduction(BlogInfo info)
        {
            //info.DateModified = DateTime.Now;
            //return _Blog.UpdateBlogIntroduction(info);
            throw new NotImplementedException();
        }

        public int UpdateBlogDeclaration(BlogInfo info)
        {
            //info.DateModified = DateTime.Now;
            //return _Blog.UpdateBlogDeclaration(info);
            throw new NotImplementedException();
        }

        public int UpdateBlogPassword(BlogInfo info)
        {
            //info.DateModified = DateTime.Now;
            //return _Blog.UpdateBlogPassword(info);
            throw new NotImplementedException();
        }
        #endregion
    }
}
